/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Алексей
 */

package ru.amse.podolsky.fractalarch;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       if(args.length != 0){
        if (args[0].charAt(0) == '-' && args[0].charAt(1) == 'c'){
           try{
               System.out.println("Please wait while file is compressed.");
               ImagesIO inputImg = new ImagesIO(args[1]);
               Compression compression = new Compression(inputImg.read(), args[3]);
               DomenParams[] toWrite = compression.compress();
               ArchivIO arch = new ArchivIO(args[2]);
               arch.write(toWrite, compression.getNumberOfDomens(), compression.getMiddleColor(), compression.getImageWidth(), compression.getImageHeight(), args[3]);
           }catch(IOException e){}
        }else{
            if(args[0].charAt(0) == '-' && args[0].charAt(1) == 'd'){
                try{
                    System.out.println("Please wait while file is decompressed.");
                    ArchivIO arch = new ArchivIO(args[1]);
                    ArrayExtractor extractor = new ArrayExtractor(arch.read());
                    Compression compression = extractor.extractCompressFromArray();
                    BufferedImage imageToWrite = compression.decompress(extractor.extractParamsFromArray(), extractor.extractStepFromArray());
                    ImagesIO outputImg = new ImagesIO(args[2]);
                    outputImg.write(imageToWrite);
                }catch(IOException e){}       
            }else{
                System.out.println("Incorrect key. Please use -c to compress and -d to decompress image.");
            }
             }
        }else{
            System.out.println("Please input parametrs.");
        }
        
    }
}
